<?php
class Zfb_Acl_Resource extends Zend_Acl_Resource
{
	/**
     * Sets the Resource identifier
     *
     * @param  stdClass $resource db row
     * @return void
     */
    public function __construct($resource)
    {
        parent::__construct($this->_getFullResourceId($resource));
    }
    
	/**
	 * Generated full name of resource from DB row 
	 * ("module-controller-action" by default)
	 * @param stdClass $resource db row
	 * @return string
	 */
	protected function _getFullResourceName($resource)
	{
		$parts = array();
		if ($resource->module) {
			$part[] = $resource->module;
			if ($resource->controller) {
				$part[] = $resource->controller;
				if ($resource->action) {
					$part[] = $resource->action;
				}
			}
		} else {
			throw new Zfb_Exception('At least one of following must be specified: module, controller, action');
		}
		
		// allowed: module | module-controller | module-controller-action
		// disallowed: module-action | controller-action | empty
		return implode('-',$pars);
	}
}